<?php
require_once(dirname(__FILE__) . '/' . 'notification/android/AndroidBroadcast.php');
require_once(dirname(__FILE__) . '/' . 'notification/android/AndroidFilecast.php');
require_once(dirname(__FILE__) . '/' . 'notification/android/AndroidGroupcast.php');
require_once(dirname(__FILE__) . '/' . 'notification/android/AndroidUnicast.php');
require_once(dirname(__FILE__) . '/' . 'notification/android/AndroidCustomizedcast.php');
require_once(dirname(__FILE__) . '/' . 'notification/ios/IOSBroadcast.php');
require_once(dirname(__FILE__) . '/' . 'notification/ios/IOSFilecast.php');
require_once(dirname(__FILE__) . '/' . 'notification/ios/IOSGroupcast.php');
require_once(dirname(__FILE__) . '/' . 'notification/ios/IOSUnicast.php');
require_once(dirname(__FILE__) . '/' . 'notification/ios/IOSCustomizedcast.php');

class Umeng {

    protected $android_appkey = '58c0cbb0734be47160001c8c';
    protected $android_appMasterSecret = 'wa8l6cf5xmkalopetesgmkpripfd6htk';
    protected $ios_appkey = '';
    protected $ios_appMasterSecret = '';
    protected $timestamp = NULL;
    protected $validation_token = NULL;

    public function __construct() {
        $this->timestamp = time();
    }
    
    public function androidSend($params){
        try{
            $customizedcast = new AndroidCustomizedcast();
            $customizedcast->setAppMasterSecret($this->android_appMasterSecret);
            $customizedcast->setPredefinedKeyValue("appkey", $this->android_appkey);
            $customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp);
            switch ($params['type']){
                case 'customizedcast': //单播
                    $customizedcast->setPredefinedKeyValue("alias_type", $params['alias_type']);
                    $customizedcast->setPredefinedKeyValue("alias", $params['alias']);
                    $customizedcast->setPredefinedKeyValue("display_type", $params['display_type']);
                    $customizedcast->setPredefinedKeyValue("ticker", $params['ticker']);
                    $customizedcast->setPredefinedKeyValue("title", $params['title']);
                    $customizedcast->setPredefinedKeyValue("text", $params['text']);
                    $customizedcast->setPredefinedKeyValue("after_open", 'go_app');
                    $result = $customizedcast->send();
                    return $result;
                    break;
            }
        } catch (Exception $ex) {
            return array('success' => false, 'msg' => $ex->getMessage());
        }
    }
    
    public function iosSend($params){
        try {
            $customizedcast = new IOSCustomizedcast();
            $customizedcast->setAppMasterSecret($this->ios_appMasterSecret);
            $customizedcast->setPredefinedKeyValue("appkey",           $this->ios_appkey);
            $customizedcast->setPredefinedKeyValue("timestamp",        $this->timestamp);
            switch ($params['type']){
                case 'customizedcast': //单播
                    $customizedcast->setPredefinedKeyValue("alias", $params['alias']);
                    $customizedcast->setPredefinedKeyValue("alias_type", $params['alias_type']);
                    $customizedcast->setPredefinedKeyValue("alert", $params['title']);
                    $customizedcast->setPredefinedKeyValue("badge", 0);
                    $customizedcast->setPredefinedKeyValue("sound", "chime");
                    $customizedcast->setPredefinedKeyValue("production_mode", "false");
                    $result = $customizedcast->send();
                    return $result;
                    break;
            }

        } catch (Exception $e) {
            return array('success' => false, 'msg' => $e->getMessage());
        }
    }

}